package com.mavenq.fly.business.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.mavenq.fly.business.entity.OperationLog;

public interface LogService {
    OperationLog saveLog(OperationLog log);

    default String filterSensitiveInfo(String jsonStr) {
        if (jsonStr == null) return null;
        return jsonStr.replaceAll("\"(password|pwd|token|secretKey|authCode|creditCard|idCard|phone|mobile|email)\":\"[^\"]*\"",
                "\"$1\":\"******\"");
    }

    default String prettyJson(Object object) {
        try {
            return JSON.toJSONString(object,
                    SerializerFeature.PrettyFormat,
                    SerializerFeature.WriteMapNullValue,
                    SerializerFeature.WriteDateUseDateFormat);
        } catch (Exception e) {
            return "JSON序列化失败: " + e.getMessage();
        }
    }
}
